<?
    /***********************************************
     * CGL/Message : For displaying the different
     * types of messages
     * ---------------------------------------------
     * (c) 2007 - Joe Chrzanowski
     * ---------------------------------------------
     * This is for displaying different types of 
     * messages on screen while making them look 
     * pretty.
     ***********************************************/
     
    class Message extends HTMLControl {
        private $_title;
        private $_message;
        
        function __construct($title,$message) {
            parent::__construct("div");
            
            $this->_title = $title;
            $this->_message = $message;
            
            // Create the header and render it
            $header = new HTMLElement("div", stripslashes($this->_title));
            $header->attributes->Set('class','message_title');
            $this->AddChild($header);
            
            // Create the text and render it
            $message = new HTMLElement("div", stripslashes($this->_message));
            $message->attributes->Set('class','message_text');
            $this->AddChild($message);
        }
    }
    class MiniMessage extends HTMLControl {
        function __construct($message,$severity) {
            parent::__construct("li",stripslashes($message));
            $this->SetAttribute('class',$severity);
        }
    }
    
    class SuccessMessage {
        static function Show($title,$message,$return = false) {
            $message = new Message($title,$message);
            $message->SetAttribute('class','message success');
            $message->styles->background = "#DDFFDD url(" . ThemeManager::GetImage("Success") . ") no-repeat 10px 10px";
            if ($return) return $message;
            else echo $message->__toString();
        }
    }
    class InfoMessage {
        static function Show($title,$message,$return = false) {
            $message = new Message($title,$message);
            $message->SetAttribute('class','message info');
            $message->styles->background = "#DDDDFF url(" . ThemeManager::GetImage("Info") . ") no-repeat 10px 10px";
            if ($return) return $message;
            else echo $message->__toString();
        }
    }
    class WarningMessage {
        static function Show($title,$message,$return = false) {
            $message = new Message($title,$message);
            $message->SetAttribute('class','message warning');
            $message->styles->background = "#FFFFDD url(" . ThemeManager::GetImage("Warning") . ") no-repeat 10px 10px";
            if ($return) return $message;
            else echo $message->__toString();
        }
    }
    // the errormessage class also provides an interface to the logging and error reporting systems
    // when an error message occurs, the page, user, variables, etc. are stored for future review.
    class ErrorMessage {
        static function Show($title,$messagetext,$return = false) {
            $message = new Message($title,$messagetext);
            $message->SetAttribute('class','message error');
            $message->styles->background = "#FFDDDD url(" . ThemeManager::GetImage("Error") . ") no-repeat 10px 10px";
            
            // log the error
            if (strpos($_SERVER['SCRIPT_NAME'],"log.php") === false) {
            $arr = array(
                "page" => $_SERVER["SCRIPT_NAME"],
                "querystring" => $_SERVER["QUERY_STRING"],
                "postdata" => print_r($_POST,true),
                "cookie" => print_r($_COOKIE,true),
                "session" => print_r($_SESSION,true),
                "userid" => (isset($_SESSION['userid']) ? AuthManager::GetUserID() : 0),
                "time" => time(),
                "error" => $title,
                "message" => $messagetext
            );
            DBM::Execute(QueryTools::CreateQuery($arr,"log"));
            }
            
            if ($return) return $message;
            else {
                if (!Conf::$PrintedHeader)
                    Functions::PrintHeader("Error");
                    
                echo $message->__toString();
            }
        }
    }
    class FatalMessage {
        static function Show($title,$message) {
            $message = new Message($title,$message);
            $message->SetAttribute('class','message error');
            $message->styles->background = "#FFDDDD url(" . ThemeManager::GetImage("Error") . ") no-repeat 10px 10px";
            echo $message->__toString();
            //throw new ComplexException($title,$message);
        }
    }
?>
